﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Audio;
using LNUGame.Controller;
using Microsoft.Xna.Framework.Media;

namespace LNUGame.View
{
    /// <summary>
    /// Class to control the playing, pausing and stopping of sounds
    /// </summary>
    class GameSound : ISoundObserver
    {
        private SoundEffect m_painEnemy;
        private SoundEffect m_painSpikes;
        private SoundEffect m_pickupPill;
        private SoundEffect m_enemyKilled;
        private Song m_ambientRain;
        private bool m_isRainSoundPlaying = false;


        /// <summary>
        /// Main constructor.
        /// Loads all the sounds into memory.
        /// </summary>
        /// <param name="a_contentManager">The ContentManager to use</param>
        public GameSound(ContentManager a_contentLoader)
        {
            m_painEnemy = a_contentLoader.Load<SoundEffect>("sounds/pain_enemy");
            m_painSpikes = a_contentLoader.Load<SoundEffect>("sounds/pain_spikes");

            m_pickupPill = a_contentLoader.Load<SoundEffect>("sounds/pickup_pill");

            m_enemyKilled = a_contentLoader.Load<SoundEffect>("sounds/enemy_killed");

            m_ambientRain = a_contentLoader.Load<Song>("sounds/ambient_rain");
            MediaPlayer.IsRepeating = true;
        }


        /// <summary>
        /// Starts the ambient rain
        /// </summary>
        internal void StartAmbientRain()
        {
            MediaPlayer.Play(m_ambientRain);
            m_isRainSoundPlaying = true;
        }


        /// <summary>
        /// Stops the ambient rain
        /// </summary>
        internal void StopAmbientRain()
        {
            MediaPlayer.Stop();
            m_isRainSoundPlaying = false;
        }


        /// <summary>
        /// Getter for if the rain is playing
        /// </summary>
        public bool RainSoundIsPlaying
        {
            get
            {
                return m_isRainSoundPlaying;
            }
        }


        /// <summary>
        /// Plays a sound when the player is hurt by an enemy
        /// </summary>
        public void PainFromEnemy()
        {
            m_painEnemy.Play();
        }


        /// <summary>
        /// Plays a sound when the player is hurt by spikes
        /// </summary>
        public void PainFromSpikes()
        {
            m_painSpikes.Play();
        }


        /// <summary>
        /// Plays a sound when the player picks up a pill
        /// </summary>
        /// <returns></returns>
        public void PickupPill()
        {
            m_pickupPill.Play();
        }


        /// <summary>
        /// Plays a sound when an enemy is killed by the player
        /// </summary>
        public void EnemyKilled()
        {
            m_enemyKilled.Play();
        }
    }
}
